package com.some;

public class BP03_test {
    //3. 多重背包问题
    //限定每件物品的数量
    private static int maxValue(int[] weight, int[] value, int[] num, int bagWeight) {
        int[] dp = new int[bagWeight + 1];

        for (int i = 0; i < weight.length; i++) {
            for (int j = bagWeight; j >= weight[i]; j--) {
                for (int k = 0; (k <= num[i]) && (k * weight[i] <= j); k++) {
                    dp[j] = Math.max(dp[j], dp[j - k * weight[i]] + k * value[i]);
                }
            }
        }
        return dp[dp.length - 1];
    }

    public static void main(String[] args) {
        System.out.println(maxValue(new int[]{1, 2, 3, 4}, new int[]{2, 4, 4, 5}, new int[]{3, 1, 3, 2}, 5));//10
    }
}
